﻿using System;
using System.Collections.Generic;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;

namespace ZLDC.Topo.BLL.Estate
{
    public class HuosingPicBLL
    {
                public  static string p_huosing_pic_insert(string picurl, string picurlSmall, string name, int type, int hid, string hestatename, string hroomno, string remark, int dltFlag)
        {
            string outmsg = "";
            int newid = 0;
            string userId = _Utility.GetInfoBySession().m_sUserID;
            string deptId = _Utility.GetInfoBySession().m_sDeptID;
            string deptName = _Utility.GetInfoBySession().m_sDeptName;
            string userName = _Utility.GetInfoBySession().m_sUserName;

            using (_Database db = new _Database("estate"))
            {
                ZLDC.DAL.Estate.HuosingPicDAL.p_huosing_pic_insert(picurl, picurlSmall, name, type, hid, hestatename, hroomno, remark, dltFlag, deptId, deptName, userId, userName, out outmsg, out  newid, db);
            }

            return outmsg;
        }
                public static string  p_huosing_pic_listall_table(int id)
        {
            DataTable dt = null;
            using (_Database db = new _Database("estate")) 
            {
                dt = ZLDC.DAL.Estate.HuosingPicDAL.p_huosing_pic_listall_table(id,db);
            }
            _Json json = new _Json(dt, "yyyy-MM-dd HH:mm:ss");        
            return "{record:" + json.ToJson() + "}";
           
        }
                public static int HousingCoutnPic(int Hid, string type)
        {
            DataTable dt = null;

            using (_Database db = new _Database("estate"))
            {
                dt = ZLDC.DAL.Estate.HuosingPicDAL.p_huosing_pic_listall_table(Hid, db);
            }
            int count = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                if (dt.Rows[i]["type"].ToString() == type)
                {
                    count = count + 1;
                }
              
            }

            return count;
        }
                public static string DelPic(int id, string deptid)
        {
            string outmsg = "";
            int rows = 0;
            using (_Database db = new _Database("estate"))
            {
                rows = ZLDC.DAL.Estate.HuosingPicDAL.DelPic(id, deptid, db);
                if (rows > 0)
                {
                    outmsg = "删除成功";
                    ZLDC.Topo.BLL.Estate.OperationlogBLL.p_operationlog_insert("t_housing_pic", id, 3, "删除图片");
                }
                else
                {
                    outmsg = "对不起，你没有权限删除该图片！";
                }
            }
            return outmsg;
        }


        public static int IsExitHousingPicToday(int id) 
        {
            using (_Database db = new _Database("estate")) 
            {
                return ZLDC.DAL.Estate.HuosingPicDAL.IsExitHousingPicToday(id, db);
            }
        }
    }
}
